package com.zzyl.mapper;

import com.zzyl.dto.ResourceDto;
import com.zzyl.entity.Resource;
import com.zzyl.vo.MenuVo;
import com.zzyl.vo.ResourceVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ResourceMapper {

    int deleteByPrimaryKey(Long id);

    int insert(Resource record);

    int insertSelective(Resource record);

    Resource selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Resource record);

    int updateByPrimaryKey(Resource record);

    /**
     * 这是Mybatis Generator拓展插件生成的方法(请勿删除).
     * This method corresponds to the database table sys_resource
     *
     * @mbg.generated
     * @author hewei
     */
    int batchInsert(@Param("list") List<Resource> list);

    /**
     * 查询子菜单列表
     * @param resource
     * @return
     */
    List<Resource> selectResourceList(ResourceDto resource);

    /**
     * 根据资源编号查询菜单
     * @param parentResourceNo
     * @return
     */
    @Select("select * from zzyl.sys_resource where resource_no = #{parentResourceNo}")
    Resource selectDataStateByResourceNo(String parentResourceNo);

    /**
     * 统计子资源列表数量
     * @param resourceNo
     * @return
     */
    @Select("select count(1) from zzyl.sys_resource where parent_resource_no = #{resourceNo}")
    Integer selectResourceByResourceNo(String resourceNo);

    /**
     * 更新状态
     * @param resource
     * @return
     */
    @Update("update zzyl.sys_resource set data_state = #{dataState} where resource_no = #{resourceNo}")
    Integer updateStatus(Resource resource);

    /**
     * 根据资源编号删除菜单
     * @param menuId
     */
    @Delete("delete from zzyl.sys_resource where resource_no = #{menuId}")
    void deleteByResourceNo(String menuId);

    /**
     * 根据资源编号修改状态
     * @param resourceNo
     * @param dataState
     */
    @Update("update zzyl.sys_resource set data_state = #{dataState} where resource_no = #{resourceNo} ")
    void updateByResourceNo(String resourceNo, String dataState);

    /**
     * 根据父资源编号修改状态
     * @param s
     * @param dataState
     */
    @Update("update zzyl.sys_resource set data_state = #{dataState} where parent_resource_no like concat(#{resourceNo},'%')")
    Integer updateByParentResourceNo(String s, String dataState);

    /**
     * 根据资源类型查询菜单
     * @param resourceType
     * @return
     */
    @Select("select * from zzyl.sys_resource where resource_type = #{resourceType}")
    List<Resource> selectResourceByResourceType(String resourceType);

    /**
     * 根据用户编号查询菜单
     * @param userId
     * @return
     */
    List<String> selectResourceListByUserId(Long userId);

    /**
     * 根据用户编号查询菜单
     * @param userId
     * @return
     */
    List<MenuVo> findListByUserId(Long userId);
}